﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace RoboTrocity {
	class Player : Entity {
		Gun equippedGun;
		
		
		List<Gun> guns;

		public Player() {
			

			guns = new List<Gun>();
			guns.Add(new Gun(Gun.SingleShot));
			guns.Add(new Gun(Gun.TripleShot));

			guns[0].isUnlocked = true;
			guns[1].isUnlocked = true;
			equippedGun = guns[0];

			
		}

		public List<Bullet> shoot() {
			List<Bullet> bullets = equippedGun.Shoot();
			foreach (Bullet bullet in bullets) {
				if (FacingLeft) {
					bullet.Position = new Point(Position.X + 5, Position.Y + Height / 2 - 5);
					bullet.setVelocityX(-(int)bullet.Velocity.X);
				} else {
					bullet.Position = new Point(Position.X + Width - 20, Position.Y + Height / 2 - 5);
				}
			}
			return bullets;
		}

		public void switchGun(int gunNum) {
			if (gunNum >= 0 && gunNum <= guns.Count && guns[gunNum-1].isUnlocked) {
				equippedGun = guns[gunNum-1];
			}
		}


		/// <summary>
		/// Handle collision between this Player and an Enemy.
		/// </summary>
		/// <param name="enemy">The enemy to collide with.</param>
		public override void collideWith(Enemy enemy) {
			foreach (CollisionBox attackBox in enemy.DispSprite.CollisionBoxes(CollisionBox.BoxType.ATTACK)) {
				foreach (CollisionBox hitBox in this.DispSprite.CollisionBoxes(CollisionBox.BoxType.HIT)) {
					if (hitBox.IntersectsWith(attackBox)) {
						//damage ent2 or something
					}
				}
			}
			foreach (CollisionBox attackBox in this.DispSprite.CollisionBoxes(CollisionBox.BoxType.ATTACK)) {
				foreach (CollisionBox hitBox in enemy.DispSprite.CollisionBoxes(CollisionBox.BoxType.HIT)) {
					if (hitBox.IntersectsWith(attackBox)) {
						//damage ent1 or something
					}
				}
			}
		}

		public Gun EquippedGun {
			get { return equippedGun; }
		}

		public override float ObjectDepth {
			get { return 0.2f; }
		}

		public override void Update(float timeElapsed) {
			base.Update(timeElapsed);
			EquippedGun.PassTimeSinceShot(timeElapsed);
		}
	}
}
